package mall

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"private-domain-overseas-service/app/business/api/internal/svc"
	"private-domain-overseas-service/tools/ent"
	"private-domain-overseas-service/tools/ent/hzmallsite"
	"private-domain-overseas-service/tools/ent/predicate"
)

type MallSiteDao struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewMallSiteDao(ctx context.Context, svcCtx *svc.ServiceContext) *MallSiteDao {
	return &MallSiteDao{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// MallSiteConditionsAll - 根据条件查询多个站点信息
func (l *MallSiteDao) MallSiteConditionsAll(conditions []predicate.HzMallSite) ([]*ent.HzMallSite, error) {
	Site, err := l.svcCtx.Orm.HzMallSite.Query().
		Where(conditions...).
		Order(ent.Desc(hzmallsite.FieldMallSiteSort)).
		All(l.ctx)
	if err != nil {
		return nil, err
	}
	return Site, nil
}

// MallSiteConditionsFirst - 根据条件查询单个站点信息
func (l *MallSiteDao) MallSiteConditionsFirst(conditions []predicate.HzMallSite) (*ent.HzMallSite, error) {
	Site, err := l.svcCtx.Orm.HzMallSite.Query().
		Where(conditions...).
		First(l.ctx)
	if err != nil {
		return nil, err
	}
	return Site, nil
}
